window.addEventListener('load',function(){
	
	JD_slideshow();
// 轮播图 start;
	function JD_slideshow(){
		var header = document.querySelector('.header')
		var banner = document.querySelector('.banner');
		var lis = banner.querySelectorAll('li');
		var left = header.querySelector('.left');
		var right = header.querySelector('.right');
		// 鼠标滑过 header 模块显示;
		header.addEventListener('mouseover',function(){
			// 鼠标经过时 定时器关闭;
			clearInterval(time);
			left.style.display = 'block';
			right.style.display = 'block';
		},false);
		// 鼠标滑过 header 模块隐藏;
		header.addEventListener('mouseout',function(){
			left.style.display = 'none';
			right.style.display = 'none';
			// 鼠标离开时 定时器开启;
			time = setInterval(function(){
				right.click();
			},1500)
		},false);
		
		var headerWidth = header.offsetWidth;
		var circle = document.querySelector('.circle');
		// 有多少个图片 创建多少个 圆;
		for(var i = 0; i < banner.children.length; i++){
			// 创建 小li;
			var circle_li = document.createElement('li');
			// 将小 li 放到 ol 里面;
			circle.appendChild(circle_li);
			// 先给第一个 圆 给css样式 让他背景变白色;
			circle.children[0].className = 'cuttren';
			// 排他 干掉所有 留下自己;
			circle.children[i].addEventListener('click',function(){
				for(var i = 0; i < circle.children.length; i++){
					circle.children[i].className = '';
				}
				this.className = 'cuttren';
			})
			// table 切换;
			// 给每一个小圆点一个索引号;
			circle_li.setAttribute('index',i);
			// 点击小圆点事件;
			circle.children[i].addEventListener('click',function(){
				for(var i = 0; i < circle.children.length; i++){
					// banner.children[i].style.display = 'none';
				}
				// 获取小圆点索引号;
				var index = this.getAttribute('index');
				// banner.children[index].style.display = 'block';
				animate(banner,-index * headerWidth);
				console.log(headerWidth);
			})
		}
		var frist = banner.children[0].cloneNode(true);
		banner.appendChild(frist);
		// console.log(frist);
		// num 控制滚动;
		var num = 0;
		// 控制圆点;
		var cirler_num = 0;
		// 左箭头;
		left.addEventListener('click',function(){
			if(num == 0){
				// num = banner 儿子的长度减一;
				num = banner.children.length - 1;
				// 当滑过最后一张时  瞬间跳转第一张;
				banner.style.left = -num * headerWidth + 'px';
			}
			num--;
			cirler_num--;
			// console.log("yuan:" + cirler_num);
			// console.log(num);
			animate(banner,-num * headerWidth);
			cirler_num < 0 ? cirler_num = circle.children.length - 1 : cirler_num;
			commom();
		})	
		// 右箭头;
		right.addEventListener('click',function(){
			if(num == banner.children.length - 1){
				num = 0;
				banner.style.left = -num * headerWidth + 'px';
			}
			num++;
			cirler_num++;
			animate(banner,-num * headerWidth);
			// console.log("yuan:" + cirler_num);
			// console.log(num);
			cirler_num == circle.children.length ? cirler_num = 0 : cirler_num;
			commom();
		})
		// 左右箭头 排他公共样式;
		function commom(){
			for(var i = 0; i < circle.children.length; i++){
				circle.children[i].className = '';
			}
			circle.children[cirler_num].className = 'cuttren';
		}
		var time = setInterval(function(){
			// 调用 右箭头事件;
			right.click();
		},1500)
	}
// 轮播图 end;
	// 程序一上来 立马调用; 不调用会出现 空白时间效果;
		count_down("2021/11/6 00:00:00");
		function count_down(time) {
		   let span = document.querySelectorAll('.times');
		   const spanArr = [...span];
		   let nowtime = new Date();  //获取当前时间
		   let endtime = new Date(time);  //定结束时间
		   let times = endtime - nowtime;  //距离结束时间的毫秒数
		   let h = Math.floor(times/(1000*60*60)%24);  //计算小时数
		   let m = Math.floor(times/(1000*60)%60);  //计算分钟数
		   let s = Math.floor(times/1000%60);  //计算秒数
			   h = h < 10 ? '0' + h : h;
			   m = m < 10 ? '0' + m : m;
			   s = s < 10 ? '0' + s : s;
			// 停止计时器;
			if(h == '00' && m == '00' && s == '00'){
				clearInterval(_time);
			}
			let re = h + '' + m + s;
			 spanArr[0].innerHTML = re.substr(0,1);
			 spanArr[1].innerHTML = re.substr(1,1);
			 spanArr[2].innerHTML = re.substr(2,1);
			 spanArr[3].innerHTML = re.substr(3,1);
			 spanArr[4].innerHTML = re.substr(4,1);
			 spanArr[5].innerHTML = re.substr(5,1);
			return h + ":" + m + ":" + s;  //返回倒计时的字符串
		}
		// count_down("2021/11/5 00:00:00")
		var _time = setInterval(function(){
			count_down("2021/11/6 00:00:00")
			// console.log();
		},1000)
		
})